package net.asrsmid.invoker.as;

/**
 * A CoordinatesOutOfBoundException is thrown when the required coordinates exceeds the table's bound 
 * @author Chen WANG
 * @since 20 June 2011
 */
public class CoordinatesOutOfBoundException extends TableException {
	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructs a CoordinatesOutOfBoundException when the given fields
	 * @param coords an int array indicating the required coordinates
	 * @param dims an int array representing table's dimension and the length of each dimension
	 */
	public CoordinatesOutOfBoundException(int[] coords, int[] dims) {
		super(composeMsg(coords, dims));
	}
	
	private static String composeMsg(int[] coords, int[] dims) {
		StringBuilder sb = new StringBuilder();
		
		sb.append("Coordinates ").append(coords.toString());
		sb.append(" out of bound [");
		for (int i = 0; i < dims.length; i++) {
			sb.append(dims[i] - 1);
			if (i < dims.length - 1)
				sb.append(" ");
		}
		sb.append("]");
		
		return sb.toString();
	}
}
